Integrate startup scripts in CMake install process with automatic init system detection#136
Conversation
@copilot GO! |
Co-authored-by: clauspruefer <17313789+clauspruefer@users.noreply.github.com>
Co-authored-by: clauspruefer <17313789+clauspruefer@users.noreply.github.com>
clauspruefer
left a comment
There was a problem hiding this comment.
Looks goog, comprehensive tests following on v0.1.1rc.
There was a problem hiding this comment.
Pull Request Overview
This PR implements automatic startup script installation during the CMake install process, detecting the Linux init system type and installing the appropriate service configuration without user intervention.
- Automatic init system detection (systemd, OpenRC, or SysVinit) based on filesystem characteristics
- Installation of the correct startup script to appropriate system directories with proper permissions
- Clear post-installation instructions displayed to users for service management
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| scripts/install_startup_script.cmake | New CMake script implementing init system detection and startup script installation logic |
| CMakeLists.txt | Added invocation of the startup script installation during make install |
| README.md | Updated Quick Start guide to include systemd service management commands |
| BUILD.md | Enhanced installation documentation with comprehensive service management instructions for all init systems |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
|
||
| # Detect OpenRC | ||
| elseif((EXISTS "/etc/init.d" AND EXISTS "/etc/runlevels") OR EXISTS "/sbin/openrc-run" OR EXISTS "/usr/sbin/openrc-run") | ||
| set(INIT_SYSTEM "openrc") | ||
| set(INIT_SCRIPT_SRC "${CMAKE_CURRENT_LIST_DIR}/startup/openrc/falcon-as") | ||
| set(INIT_SCRIPT_DEST "/etc/init.d/falcon-as") | ||
| message(STATUS "Detected init system: OpenRC") | ||
|
|
||
| # Fallback to SysVinit | ||
| elseif(EXISTS "/etc/init.d") | ||
| set(INIT_SYSTEM "sysvinit") | ||
| set(INIT_SCRIPT_SRC "${CMAKE_CURRENT_LIST_DIR}/startup/init.d/falcon-as") | ||
| set(INIT_SCRIPT_DEST "/etc/init.d/falcon-as") | ||
| message(STATUS "Detected init system: SysVinit") | ||
|
|
There was a problem hiding this comment.
[nitpick] The OpenRC detection logic is complex and could benefit from being split into separate conditions for better readability. Consider breaking this into multiple elseif statements or storing intermediate boolean variables.
| # Detect OpenRC | |
| elseif((EXISTS "/etc/init.d" AND EXISTS "/etc/runlevels") OR EXISTS "/sbin/openrc-run" OR EXISTS "/usr/sbin/openrc-run") | |
| set(INIT_SYSTEM "openrc") | |
| set(INIT_SCRIPT_SRC "${CMAKE_CURRENT_LIST_DIR}/startup/openrc/falcon-as") | |
| set(INIT_SCRIPT_DEST "/etc/init.d/falcon-as") | |
| message(STATUS "Detected init system: OpenRC") | |
| # Fallback to SysVinit | |
| elseif(EXISTS "/etc/init.d") | |
| set(INIT_SYSTEM "sysvinit") | |
| set(INIT_SCRIPT_SRC "${CMAKE_CURRENT_LIST_DIR}/startup/init.d/falcon-as") | |
| set(INIT_SCRIPT_DEST "/etc/init.d/falcon-as") | |
| message(STATUS "Detected init system: SysVinit") | |
| # Prepare OpenRC detection variables for readability | |
| set(OPENRC_DIR_DETECTED FALSE) | |
| set(OPENRC_BIN_DETECTED FALSE) | |
| if(EXISTS "/etc/init.d" AND EXISTS "/etc/runlevels") | |
| set(OPENRC_DIR_DETECTED TRUE) | |
| endif() | |
| if(EXISTS "/sbin/openrc-run" OR EXISTS "/usr/sbin/openrc-run") | |
| set(OPENRC_BIN_DETECTED TRUE) | |
| endif() | |
| # Detect OpenRC | |
| elseif(OPENRC_DIR_DETECTED OR OPENRC_BIN_DETECTED) | |
| set(INIT_SYSTEM "openrc") | |
| set(INIT_SCRIPT_SRC "${CMAKE_CURRENT_LIST_DIR}/startup/openrc/falcon-as") | |
| set(INIT_SCRIPT_DEST "/etc/init.d/falcon-as") | |
| message(STATUS "Detected init system: OpenRC") | |
| # Fallback to SysVinit | |
| elseif(EXISTS "/etc/init.d") | |
| set(INIT_SYSTEM "sysvinit") | |
| set(INIT_SCRIPT_SRC "${CMAKE_CURRENT_LIST_DIR}/startup/init.d/falcon-as") | |
| set(INIT_SCRIPT_DEST "/etc/init.d/falcon-as") | |
| message(STATUS "Detected init system: SysVinit") |
| message(WARNING "Could not detect init system. Defaulting to SysVinit.") | ||
| set(INIT_SYSTEM "sysvinit") | ||
| set(INIT_SCRIPT_SRC "${CMAKE_CURRENT_LIST_DIR}/startup/init.d/falcon-as") | ||
| set(INIT_SCRIPT_DEST "/etc/init.d/falcon-as") |
There was a problem hiding this comment.
[nitpick] The fallback logic duplicates the SysVinit configuration from lines 24-26. Consider extracting this into a function or variable to avoid code duplication.
| RESULT_VARIABLE CHMOD_RESULT | ||
| ) | ||
| if(CHMOD_RESULT EQUAL 0) | ||
| message(STATUS "✓ Made script executable") |
There was a problem hiding this comment.
The chmod failure case is not handled. Consider adding an else clause to warn the user if the chmod operation fails, as this could prevent the service from starting properly.
| message(STATUS "✓ Made script executable") | |
| message(STATUS "✓ Made script executable") | |
| else() | |
| message(WARNING "Failed to make script executable: ${INIT_SCRIPT_DEST}") | |
| message(WARNING "You may need to run 'chmod +x ${INIT_SCRIPT_DEST}' with sudo/root privileges.") |
Overview
This PR implements automatic detection and installation of startup scripts during the CMake install process. The system now automatically detects the Linux init system type (systemd, OpenRC, or SysVinit) and installs the appropriate startup script without any user intervention.
Problem
Previously, users had to manually:
scripts/startup/This manual process was error-prone and required knowledge of different init systems.
Solution
Added a CMake script (
scripts/install_startup_script.cmake) that runs duringmake installand:/run/systemd/systemor/usr/lib/systemd/system/etc/runlevels,/sbin/openrc-run, or/usr/sbin/openrc-run/etc/init.d(fallback)/etc/systemd/system/falcon-as.service/etc/init.d/falcon-as/etc/init.d/falcon-asChanges
New Files
scripts/install_startup_script.cmake- Detection and installation logicModified Files
CMakeLists.txt- Added single line to invoke the install scriptBUILD.md- Updated installation instructions with service management commands for all init systemsREADME.md- Updated Quick Start guide to show systemd service managementExample Output
After running
sudo make install, users see:Supported Distributions
Benefits
Testing
Comprehensive testing performed:
Closes #[issue-number]
Original prompt
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.